
#ifndef _Minicom_Client_h_
#define _Minicom_Client_h_

#include <boost/asio.hpp> 
#include <deque> 
#include <QObject>

#ifdef POSIX 
#include <termios.h> 
#endif 

namespace vkbrd
{
	class miniComClient :public QObject
	{ 
		Q_OBJECT;

		friend class QtAsioThread;

	public: 

		miniComClient(boost::asio::io_service& io_service, unsigned int baud, const std::string& device); 

		~miniComClient();

		static const int maxReadLength = 512; // maximum amount of data to read in one operation 

		void poll();

	signals:
	
		void receivedData(unsigned char* read_msg_, int bytes_transferred );

	private: 

		void read_start(void); 

		void read_complete(const boost::system::error_code& error, int bytes_transferred); 

		void do_write(unsigned char msg); 

		void write_start(void); 

		void write_complete(const boost::system::error_code& error); 

		void do_close(const boost::system::error_code& error); 

	private: 
		boost::asio::serial_port serialPort; // the serial port this instance is connected to 
		char read_msg_[maxReadLength]; // data read from the socket 
		std::deque<unsigned char> writeMsgs; // buffered write data 
		boost::asio::io_service& ioService; // the main IO service that runs this connection 
	}; 
} //namespace vkbrd

#endif